// AnsiEditorDoc.h : interface of the CAnsiEditorDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_ANSIEDITORDOC_H__C07975CC_FFE8_11D7_B08F_0002553118A0__INCLUDED_)
#define AFX_ANSIEDITORDOC_H__C07975CC_FFE8_11D7_B08F_0002553118A0__INCLUDED_

#include "CellInfo.h"	// Added by ClassView
#include "AnsiPage.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CAnsiEditorSrvrItem;

extern int MAX_COL;
extern int MAX_ROW;
//extern int 

#define IsGBKByte(x) (((BYTE)x) > 0x80)

class CAppContext;
class CAnsiEditorDoc : public COleServerDoc
{
public:
	typedef struct tagDocProperties
	{
		CString sAuthor;
		CString sKeywords;
		CString sComment;
		void Reset()
		{
			sAuthor.Empty();
			sKeywords.Empty();
			sComment.Empty();
		}
	} DocProperties;
protected: // create from serialization only
	BOOL IsHtmlExt(const CString& fileName);
	CString GetDocAnsText();
	CAnsiEditorDoc();
	DECLARE_DYNCREATE(CAnsiEditorDoc)

// Attributes
public:
	BOOL OpenDocumentFromFile(LPCTSTR lpszPathName);
	void CheckRecover();
	void SaveRecover();
	void SetExtent(CSize size);
	BOOL m_bNotifiedChanged;
	void CheckNotifyChanged();

	BOOL m_bShowingEmbbed;
	CAppContext *gpUIContext;
	CAnsiEditorSrvrItem* GetEmbeddedItem()
		{ return (CAnsiEditorSrvrItem*)COleServerDoc::GetEmbeddedItem(); }

	DocProperties m_properties;

// Operations
public:
	static BOOL IsGBKFirstByte(const char *szBuf, int x)
	{
		const char *pc0 = szBuf;
		if((BYTE)pc0[x] > 0x80)
		{
			const char *pc = pc0;
			while(pc < pc0 + x)
			{
				pc = CharNext(pc);
			}
			return (pc == pc0 + x);
		}
		else
		{
			return FALSE;
		}
	}
	static BOOL IsGBKSecondByte(const char *szBuf, int x)
	{
		if(x)
		{
			return IsGBKFirstByte(szBuf, x - 1);
		}
		return FALSE;
	}
//	static BOOL IsGBKFirstByte(const char *szBuf, int x);
//	static BOOL IsGBKSecondByte(const char *szBuf, int x);
	BOOL IsGBKFirstByte(CPoint &pt)
	{
		return IsGBKFirstByte(pt.y, pt.x);
	}
	BOOL IsGBKFirstByte(int y, int x);
	BOOL IsGBKSecondByte(CPoint &pt)
	{
		return IsGBKSecondByte(pt.y, pt.x);
	}
	BOOL IsGBKSecondByte(int y, int x)
	{
		if(x)
		{
			return IsGBKFirstByte(y, x - 1);
		}
		return FALSE;
	}
	void FillRegion(CRect rect, const CString &sText);

// Overrides

	virtual void SetModifiedFlag(BOOL bModified = TRUE);
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAnsiEditorDoc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	virtual void DeleteContents();
	virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
	virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
	virtual BOOL IsModified();
	protected:
	virtual COleServerItem* OnGetEmbeddedItem();
	virtual BOOL SaveModified();
	//}}AFX_VIRTUAL


// Implementation
public:
	CString msRecoverFilename;
	CAnsiPage* GetActivePage();
	CEditHistory* m_pHistory;
	void SetActivePage(int nPage, BOOL bSaveToPageHistory = TRUE, BOOL bSaveCurCaretPos = TRUE);
	BOOL SetNewSize(int nNewMaxCol, int nNewMaxRow);
	CCellInfo **m_cells;//[MAX_ROW][MAX_COL];
	CHAR	  **m_chars;//[MAX_ROW][MAX_COL];
	typedef CArray<CAnsiPage*, CAnsiPage*> PageArray;
	PageArray m_arrPages;
	int		  m_nPageCount;
	int		  m_nCurPage;
	virtual ~CAnsiEditorDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	virtual CDocObjectServer* GetDocObjectServer(LPOLEDOCUMENTSITE pDocSite);
	virtual BOOL DoSave(LPCTSTR lpszPathName, BOOL bReplace = TRUE);

// Generated message map functions
protected:
	CString GetDelayAnimate(int nTimingBase, int nMaxLineLen);
	CString GetFrameAnimate(BOOL bGenerateProlog, CString sProlog, BOOL bAutoInsertFrame, int nFrameLineCount);
	BOOL OpenSimpleDocument(LPCTSTR lpszPathName);
	CIntArray m_arrPageHistory;
	int m_nPageHistoryIndex;
	BOOL InitDocument();
	//{{AFX_MSG(CAnsiEditorDoc)
	afx_msg void OnAnimateNewFrame();
	afx_msg void OnAnimateDeleteFrame();
	afx_msg void OnUpdateAnimateDeleteFrame(CCmdUI* pCmdUI);
	afx_msg void OnUpdateAnimateNextPage(CCmdUI* pCmdUI);
	afx_msg void OnUpdateAnimatePrevPage(CCmdUI* pCmdUI);
	afx_msg void OnAnimateDuplicate();
	afx_msg void OnUpdateAnimateDupPreframe(CCmdUI* pCmdUI);
	afx_msg void OnAnimateDupPreframe();
	afx_msg void OnUpdateAnimateDupNextframe(CCmdUI* pCmdUI);
	afx_msg void OnAnimateDupNextframe();
	afx_msg void OnPageProperty();
	afx_msg void OnUpdateNextPage(CCmdUI* pCmdUI);
	afx_msg void OnNextPage();
	afx_msg void OnUpdatePrevPage(CCmdUI* pCmdUI);
	afx_msg void OnPrevPage();
	afx_msg void OnUpdateForwardPage(CCmdUI* pCmdUI);
	afx_msg void OnForwardPage();
	afx_msg void OnBackwordPage();
	afx_msg void OnUpdateBackwordPage(CCmdUI* pCmdUI);
	afx_msg void OnUpdateExportAnimate(CCmdUI* pCmdUI);
	afx_msg void OnExportAnimate();
	afx_msg void OnUpdateFirstPage(CCmdUI* pCmdUI);
	afx_msg void OnFirstPage();
	afx_msg void OnUpdateLastPage(CCmdUI* pCmdUI);
	afx_msg void OnLastPage();
	afx_msg void OnFileProperty();
	afx_msg void OnAnimatePreview();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ANSIEDITORDOC_H__C07975CC_FFE8_11D7_B08F_0002553118A0__INCLUDED_)
